import 'package:flutter/material.dart';

import '../../../../../helper/global/user/logic.dart';
import '../../../../../helper/utils/util.dart';
import '../../../../login/main/widgets/code_field.dart';
import 'controller.dart';

class NewPwdPage extends GetView<NewPwdController> {
  const NewPwdPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    return Scaffold(
      // appBar: detailAppBar(context, elevation: 1, title: '忘记密码'),
      body: Container(
        // decoration: BoxDecoration(
        //   image: DecorationImage(
        //     image: loadImageProvider(url: 'log_bg.png'.imgPathCommon),
        //     fit: BoxFit.cover,
        //   ),
        // ),
        padding: EdgeInsets.symmetric(horizontal: 31.w),
        child: ListView(
          // crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            SafeArea(
              child: SizedBox(
                height: 20.r,
              ),
            ),
            Container(
              alignment: Alignment.centerLeft,
              // margin: EdgeInsets.only(left: 30.r),
              child: Text(
                '忘记密码',
                style: TextStyle(
                  color: Colors.black,
                  fontSize: 30.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            Container(
              alignment: Alignment.center,
              height: 40.r,
              child: Text(
                state.appName,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 18.sp,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
            SizedBox(
              height: 20.r,
            ),
            UITextField(
              title: '手机号',
              hintText: '请输入手机号',
              onChanged: (value) {
                state.account = value;
              },
              titleStyle: TextStyle(
                color: const Color(0xff333333),
                fontSize: 20.sp,
                fontWeight: FontWeight.bold,
              ),
              keyboardType: TextInputType.phone,
              style: TextFieldStyle.underLine,
            ),
            SizedBox(
              height: 20.r,
            ),
            Container(
              alignment: Alignment.centerLeft,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '验证码',
                      style: TextStyle(
                        color: const Color(0xff333333),
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  SizedBox(
                    height: 50.r,
                    child: ICodeField(
                      smsClickListener: controller.requestForSendCode,
                      isLineStyle: true,
                      margin: 0,
                      fillColor: Colors.transparent,
                      onChange: (p0) {
                        controller.update();
                      },
                    ),
                  ),
                ],
              ),
            ),
            SizedBox(
              height: 20.r,
            ),
            Obx(() => UITextField(
                style: TextFieldStyle.underLine,
                titleStyle: TextStyle(
                  color: const Color(0xff333333),
                  fontSize: 20.sp,
                  fontWeight: FontWeight.bold,
                ),
                title: '新密码',
                hintText: '请输入新密码',
                onChanged: (value) {
                  state.pwd = value;
                },
                obscureText: controller.state.obscureText.value,
                onSuffixTap: (_) {
                  controller.state.obscureText.value =
                      !controller.state.obscureText.value;
                },
                suffixIcon: controller.state.obscureText.value == true
                    ? IconUtil.eye_close
                    : IconUtil.eye_open)),
            SizedBox(
              height: 20.r,
            ),
            Obx(() => UITextField(
                  style: TextFieldStyle.underLine,
                  titleStyle: TextStyle(
                    color: const Color(0xff333333),
                    fontSize: 20.sp,
                    fontWeight: FontWeight.bold,
                  ),
                  title: '确认密码',
                  hintText: '请输入确认密码',
                  obscureText: controller.state.obscureText1.value,
                  onChanged: (value) {
                    state.pwd1 = value;
                  },
                  onSuffixTap: (_) {
                    controller.state.obscureText1.value =
                        !controller.state.obscureText1.value;
                  },
                  suffixIcon: controller.state.obscureText1.value == true
                      ? IconUtil.eye_close
                      : IconUtil.eye_open,
                )),
            SizedBox(
              height: 30.w,
            ),
            Column(
              children: ['提交', '返回登录']
                  .asMap()
                  .map((key, value) => MapEntry(
                        key,
                        InkWell(
                          onTap: () {
                            if (key == 1) {
                              Get.back();
                            } else {
                              // controller.toSuccess();
                              controller.actionSure();
                            }
                          },
                          child: Container(
                            height: 50.r,
                            // width: 120.r,
                            margin:
                                key != 0 ? EdgeInsets.only(top: 20.r) : null,
                            alignment: Alignment.center,
                            decoration: BoxDecoration(
                              color: key == 0
                                  ? ColorsUtil.blue
                                  : const Color(0x22004DB6),
                              borderRadius: BorderRadius.circular(5.r),
                            ),
                            child: Text(
                              value,
                              style: TextStyle(
                                color:
                                    key == 0 ? Colors.white : ColorsUtil.blue,
                                fontSize: 17.sp,
                              ),
                            ),
                          ),
                        ),
                      ))
                  .values
                  .toList(),
            )
          ],
        ),
      ),
    );
  }
}
